﻿@using CnGalWebSite.Components.Services;
@inject ImagesLargeViewService ImagesLargeViewService
@inject IDataCacheService _dataCatcheService
@inject IEventService _eventService
<div class="row">
    @foreach (var item in Model.OrderByDescending(s => s.Priority))
    {
        <div class="col-12 col-lg-6 mb-4 pointer" @onclick="()=>OnClickImage(Model.IndexOf(item))">
            <ImageCard Model="item" />
        </div>

    }
</div>

@code {
    [Parameter]
    public List<PicturesAloneViewModel> Model { get; set; } = new List<PicturesAloneViewModel>();

    public async void OnClickImage(int index)
    {
        if (_dataCatcheService.IsApp)
        {
            await _eventService.OpenNewPage(Model[index].Url);
        }
        else
        {
            await ImagesLargeViewService.ViewLargeImages(Model.Select(s => new ImagesLargeViewModel
                {
                    Note = s.Note,
                    Image = s.Url
                }).ToList(),index);
        }

    }
}
